#pragma once
#include"RBTree.h"

namespace xlf
{
	template<class K,class V>
	class Map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)// 仿函数 取 pair 的 first
			{
				return kv.first;
			}
		};

	public:
		typedef typename RBTree<K, pair<K, V>, MapKeyOfT >::Iterator iterator;

		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

		bool insert(const pair<K, V>& kv)
		{
			return _t.Insert(kv);
		}

	private:
		RBTree<K, pair<K, V>, MapKeyOfT > _t;
	};

	void test_map()
	{
		Map<string,string> m;
		m.insert({ "sort","排序" });
		m.insert({ "left","左边" });
		m.insert({ "right","右边" });
		m.insert({ "string","字符串" });
		m.insert({ "char","字符" });

		Map<string,string>::iterator it = m.begin();
		while (it != m.end())
		{
			cout << it->first << ":" << it->second << endl;;
			++it;
		}
		cout << endl;

	}
}